/**
 * 货物资料管理初始化
 */
var Goods = {
    id: "GoodsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Goods.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '货物代号', field: 'goodsId', visible: true, align: 'center', valign: 'middle'},
            {title: '货物名称', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
            {title: '规格型号', field: 'goodsModel', visible: true, align: 'center', valign: 'middle'},
            {title: '包装方式', field: 'goodsPackage', visible: true, align: 'center', valign: 'middle'},
            {title: '仓库', field: 'goodsWarehouse', visible: true, align: 'center', valign: 'middle'},
            {title: '数量单位', field: 'goodsQuantityUnit', visible: true, align: 'center', valign: 'middle'},
            {title: '重量单位', field: 'goodsWeightUnit', visible: true, align: 'center', valign: 'middle'},
            {title: '体积单位', field: 'goodsVolumeUnit', visible: true, align: 'center', valign: 'middle'},
            {title: '货物类别', field: 'goodsType', visible: true, align: 'center', valign: 'middle'},
            {title: '助词码', field: 'goodsRememberId', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Goods.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Goods.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加货物资料
 */
Goods.openAddGoods = function () {
    var index = layer.open({
        type: 2,
        title: '添加货物资料',
        area: ['850px', '400px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/goods/goods_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看货物资料详情
 */
Goods.openGoodsDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '货物资料详情',
            area: ['850px', '400px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/goods/goods_update/' + Goods.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除货物资料
 */
Goods.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/goods/delete", function (data) {
            Feng.success("删除成功!");
            Goods.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("goodsId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询货物资料列表
 */
Goods.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Goods.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Goods.initColumn();
    var table = new BSTable(Goods.id, "/goods/list", defaultColunms);
    table.setPaginationType("server");
    Goods.table = table.init();
});
